<script>
import { requestGet } from '@/api/system/common'

export default {
  name: 'IdCard',
  data() {
    return {
      queryBody: {
        page: 1,
        rows: 20,
        date1: '',
        date2: '',
        type: null
      },
      size: 0,
      loading: false,
      tableData: []
    }
  },
  created() {
    this.queryBody.page = 1
    this.queryBody.rows = 20
    this.queryBody.date1 = ''
    this.queryBody.date2 = ''
    this.queryBody.type = null
    this.initDataList()
  },
  methods: {
    handleQuery() {
      this.queryBody.page = 1
      this.initDataList()
    },
    // 第几页
    handleCurrentChange(val) {
      this.queryBody.page = val
      this.initDataList()
    },
    // 每页显示条数
    handleSizeChange(val) {
      this.queryBody.rows = val
      this.queryBody.page = 1
      this.initDataList()
    },
    // 查询数据
    initDataList() {
      this.loading = true
      requestGet('/rest/api/id-card/v2/user/list', this.queryBody)
        .then(res => {
          const { data } = res
          this.tableData = data.records
          this.size = data.totalRecord
        }).finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<template>
  <div class="custom-body">
    <div class="app-header">
      <div class="custom-item">
        <div class="custom-label">开始时间:</div>
        <div class="custom-input">
          <el-date-picker
            v-model="queryBody.date1"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择开始时间"
          />
        </div>
      </div>
      <div class="custom-item">
        <div class="custom-label">结束时间:</div>
        <div class="custom-input">
          <el-date-picker
            v-model="queryBody.date2"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择结束时间"
          />
        </div>
      </div>
      <div class="custom-item">
        <div class="custom-label">交易类型:</div>
        <div class="custom-input">
          <el-select v-model="queryBody.type" clearable filterable placeholder="请选择交易类型">
            <el-option label="全部" :value="null" />
            <el-option label="消费" :value="1" />
            <el-option label="充值" :value="2" />
            <el-option label="退款" :value="12" />
          </el-select>
        </div>
      </div>
      <div class="custom-item">
        <el-button :loading="loading" type="primary" @click="handleQuery">查询</el-button>
      </div>
    </div>
    <div class="app-content">
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          prop="depName"
          label="交易场所名称/方式"
        />
        <el-table-column
          prop="newMoney"
          label="交易金额"
        />
        <el-table-column
          prop="typeName"
          label="交易类型"
        />
        <el-table-column
          prop="jlSj"
          label="交易时间"
        />
      </el-table>
    </div>
    <div class="app-footer">
      <el-pagination
        :current-page="queryBody.page"
        :page-sizes="[20, 30, 40, 50]"
        :page-size="queryBody.rows"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.custom-body {
  width: 100%;
  height: 100%;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-flow: column nowrap;
}
.app-header {
  min-height: 40px;
  width: 100%;
  display: flex;
  border-bottom: 1px solid #f2f2f2;
  flex-flow: row wrap;
  font-size: 1rem;
  font-weight: 500;
  padding-bottom: 20px;
  .custom-item {
    width: 350px;
    height: 40px;
    display: flex;
    align-items: center;
    .custom-label {
      width: 80px;
    }
  }
}
.app-content {
  width: 100%;
  flex: 1 1;
  padding-top: 20px;
}
.app-footer {
  width: 100%;
  height: 60px;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: right;
}
</style>
